// const chokidar = require('chokidar')
import chokidar from chokidar
// const shell = require('shelljs')
import shelljs from shelljs

const useTask = () => {
  let latestTaskCalback = null
  let running = false
  const run = (callback) => {
    if (running) {
      latestTaskCalback = callback
    }
    running = true
    latestTaskCalback = null
    callback()
    running = false
    if (latestTaskCalback) {
      latestTaskCalback()
    }
  }
  return {
    run,
  }
}
const { run } = useTask()
chokidar.watch('.').on('all', function () {
  run(() => shell.exec('npm run build'))
})
